using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Srvtools;

namespace cLimInvtTx
{
    public partial class Form1 : InfoForm
    {
        public Form1()
        {
            InitializeComponent();
        }
        ////////////
        public string GetToday()
        {
            return string.Format("{0:yyyyMMdd}", DateTime.Today);
        }

        public string GetNowTime()
        {

            return string.Format("{0:hhmmss}", DateTime.Now);
        }

        public string GetUser()
        {
            return CliUtils.fLoginUser;
        }

        private void bindingNavigatorEditItem_Click(object sender, EventArgs e)
        {
            
        }

        private void ibsMaster_CurrentChanged(object sender, EventArgs e)
        {
           string state = infoNavigator1.GetCurrentState();
           if (state == "Inserting" || state == "Editing" || state == "Initial" || state == "Browsed")
           {
               //修改時間顯示
               string UPDATE_TIME = ((DataRowView)ibsMaster.Current)["UPDATE_TIME"].ToString();
               if (UPDATE_TIME.Length == 6)
                infoTextBox5.Text = Convert.ToDateTime(UPDATE_TIME.Substring(0, 2) + ":" + UPDATE_TIME.Substring(2, 2) + ":" + UPDATE_TIME.Substring(4, 2)).ToLongTimeString(); 
               else if (UPDATE_TIME.Length == 0)
                   infoTextBox5.Text = "";


               //建檔時間顯示
               string CREATE_TIME = ((DataRowView)ibsMaster.Current)["CREATE_TIME"].ToString();
               if (CREATE_TIME.Length == 6)
                infoTextBox3.Text = Convert.ToDateTime(CREATE_TIME.Substring(0, 2) + ":" + CREATE_TIME.Substring(2, 2) + ":" + CREATE_TIME.Substring(4, 2)).ToLongTimeString(); 
               else if (CREATE_TIME.Length == 0)
                   infoTextBox3.Text = "";

               //庫存異動日期顯示
               string CREATE_DATE = ((DataRowView)ibsMaster.Current)["CREATE_DATE"].ToString(); ;
               string DT_VOU = ((DataRowView)ibsMaster.Current)["DT_VOU"].ToString();
               if (DT_VOU.Length == 8)
                infoTextBox6.Text = Convert.ToDateTime(CREATE_DATE.Substring(0, 4) + "/" + CREATE_DATE.Substring(4, 2) + "/" + CREATE_DATE.Substring(6, 2)).ToLongDateString(); 
           }
            

        }

        private void ibsMaster_AddingNew(object sender, AddingNewEventArgs e)
        {
            //在新增就顯示建檔時間     
            infoTextBox3.Text = DateTime.Now.ToLongTimeString();
        }

        private void ibsMaster_AfterEdit(object sender, EventArgs e)
        {
            //以string儲存
            ((DataRowView)ibsMaster.Current)["UPDATE_USER"] = CliUtils.fLoginUser;
            ((DataRowView)ibsMaster.Current)["UPDATE_DATE"] = string.Format("{0:yyyyMMdd}", DateTime.Now.Date);
            ((DataRowView)ibsMaster.Current)["UPDATE_TIME"] = string.Format("{0:hhmmss}", DateTime.Now);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //呼叫sLimInvtTx 的DeleteEr 方法，保留傳回值但不使用
            object[] back = CliUtils.CallMethod("sLimInvtTx", "DeleteEr", new object[] {0});           

        }

        private void infoNavigator1_StateChanged(object sender, InfoNavigatorStateChangedEventArgs e)
        {
            //將DateTimePicker設為不可改
            this.InfoDateTimePicker0.Enabled = false;
            this.InfoDateTimePicker1.Enabled = false;
        }

        private void bindingNavigatorAddNewItem_MouseUp(object sender, MouseEventArgs e)
        {
            //將DateTimePicker設為不可改
            this.InfoDateTimePicker0.Enabled = false;
            this.InfoDateTimePicker1.Enabled = false;
        }

    }
}

